﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;


namespace App.Bus
{
    /// <summary>
    /// 类Account。
    /// </summary>
    [Serializable]
    public partial class Account
    {
        public Account()
        { }
        #region Model
        private int _id;
        private string _accountname;
        private string _phone;
        private string _mobile;
        private string _qq;
        private string _paytaobao;
        private string _email;
        /// <summary>
        /// 
        /// </summary>
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string AccountName
        {
            set { _accountname = value; }
            get { return _accountname; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Phone
        {
            set { _phone = value; }
            get { return _phone; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Mobile
        {
            set { _mobile = value; }
            get { return _mobile; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string QQ
        {
            set { _qq = value; }
            get { return _qq; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string PayTaobao
        {
            set { _paytaobao = value; }
            get { return _paytaobao; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string Email
        {
            set { _email = value; }
            get { return _email; }
        }
        #endregion Model


        #region  Method

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Account(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Id,AccountName,Phone,Mobile,QQ,PayTaobao,Email ");
            strSql.Append(" FROM [Account] ");
            strSql.Append(" where Id=@Id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Id", DbType.Int32,4)};
            parameters[0].Value = Id;

            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    this.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AccountName"] != null && ds.Tables[0].Rows[0]["AccountName"].ToString() != "")
                {
                    this.AccountName = ds.Tables[0].Rows[0]["AccountName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Phone"] != null && ds.Tables[0].Rows[0]["Phone"].ToString() != "")
                {
                    this.Phone = ds.Tables[0].Rows[0]["Phone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Mobile"] != null && ds.Tables[0].Rows[0]["Mobile"].ToString() != "")
                {
                    this.Mobile = ds.Tables[0].Rows[0]["Mobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["QQ"] != null && ds.Tables[0].Rows[0]["QQ"].ToString() != "")
                {
                    this.QQ = ds.Tables[0].Rows[0]["QQ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayTaobao"] != null && ds.Tables[0].Rows[0]["PayTaobao"].ToString() != "")
                {
                    this.PayTaobao = ds.Tables[0].Rows[0]["PayTaobao"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "")
                {
                    this.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
            }
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {

            return DbHelperSQLite.GetMaxID("Id", "Account");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from [Account]");
            strSql.Append(" where Id=@Id ");

            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Id", DbType.Int32,4)};
            parameters[0].Value = Id;

            return DbHelperSQLite.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into [Account] (");
            strSql.Append("AccountName,Phone,Mobile,QQ,PayTaobao,Email)");
            strSql.Append(" values (");
            strSql.Append("@AccountName,@Phone,@Mobile,@QQ,@PayTaobao,@Email)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@AccountName", DbType.String,100),
					new SQLiteParameter("@Phone", DbType.String,100),
					new SQLiteParameter("@Mobile", DbType.String,100),
					new SQLiteParameter("@QQ", DbType.String,100),
					new SQLiteParameter("@PayTaobao", DbType.String,100),
					new SQLiteParameter("@Email", DbType.String,100)};
            parameters[0].Value = AccountName;
            parameters[1].Value = Phone;
            parameters[2].Value = Mobile;
            parameters[3].Value = QQ;
            parameters[4].Value = PayTaobao;
            parameters[5].Value = Email;

            DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [Account] set ");
            strSql.Append("AccountName=@AccountName,");
            strSql.Append("Phone=@Phone,");
            strSql.Append("Mobile=@Mobile,");
            strSql.Append("QQ=@QQ,");
            strSql.Append("PayTaobao=@PayTaobao,");
            strSql.Append("Email=@Email");
            strSql.Append(" where Id=@Id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@AccountName", DbType.String,100),
					new SQLiteParameter("@Phone", DbType.String,100),
					new SQLiteParameter("@Mobile", DbType.String,100),
					new SQLiteParameter("@QQ", DbType.String,100),
					new SQLiteParameter("@PayTaobao", DbType.String,100),
					new SQLiteParameter("@Email", DbType.String,100),
					new SQLiteParameter("@Id", DbType.Int32,8)};
            parameters[0].Value = AccountName;
            parameters[1].Value = Phone;
            parameters[2].Value = Mobile;
            parameters[3].Value = QQ;
            parameters[4].Value = PayTaobao;
            parameters[5].Value = Email;
            parameters[6].Value = Id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Account] ");
            strSql.Append(" where Id=@Id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Id", DbType.Int32,4)};
            parameters[0].Value = Id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Id,AccountName,Phone,Mobile,QQ,PayTaobao,Email ");
            strSql.Append(" FROM [Account] ");
            strSql.Append(" where Id=@Id ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@Id", DbType.Int32,4)};
            parameters[0].Value = Id;

            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"] != null && ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    this.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AccountName"] != null && ds.Tables[0].Rows[0]["AccountName"].ToString() != "")
                {
                    this.AccountName = ds.Tables[0].Rows[0]["AccountName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Phone"] != null && ds.Tables[0].Rows[0]["Phone"].ToString() != "")
                {
                    this.Phone = ds.Tables[0].Rows[0]["Phone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Mobile"] != null && ds.Tables[0].Rows[0]["Mobile"].ToString() != "")
                {
                    this.Mobile = ds.Tables[0].Rows[0]["Mobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["QQ"] != null && ds.Tables[0].Rows[0]["QQ"].ToString() != "")
                {
                    this.QQ = ds.Tables[0].Rows[0]["QQ"].ToString();
                }
                if (ds.Tables[0].Rows[0]["PayTaobao"] != null && ds.Tables[0].Rows[0]["PayTaobao"].ToString() != "")
                {
                    this.PayTaobao = ds.Tables[0].Rows[0]["PayTaobao"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "")
                {
                    this.Email = ds.Tables[0].Rows[0]["Email"].ToString();
                }
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM [Account] ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.Query(strSql.ToString());
        }

        #endregion  Method
    }
}

